package manager;

import entity.Student;
import iface.IManager;
import java.util.ArrayList;
import javax.swing.JOptionPane;

/**
 *
 * @author Noi
 */
public class StudentManager implements IManager<Student> {

    private ArrayList<Student> studentList;

    public StudentManager() {
        this.studentList = new ArrayList<Student>();
    }

    @Override
    public boolean add(Student student) {
        return this.studentList.add(student);
    }

    @Override
    public boolean remove(Student student) {
        return this.studentList.remove(student);
    }

    @Override
    public Student replace(int index, Student student) {
        return this.studentList.set(index, student);
    }

    @Override
    public int size() {
        return this.studentList.size();
    }

    @Override
    public Student get(int index) {
        return this.studentList.get(index);
    }

    public ArrayList<Student> getByClassID(String classID) {
        ArrayList<Student> alStudent = new ArrayList<Student>();
        for (int i = 0; i < this.studentList.size(); i++) {
            if (this.studentList.get(i).getClassID().equals(classID)) {
                alStudent.add(this.studentList.get(i));
            }
        }
        return alStudent;
    }

    @Override
    public Student getById(int id) {
        return null;
    }

    public Student getById(String id) {
        for (int i = 0; i < this.studentList.size(); i++) {
            if (id.equals(this.studentList.get(i).getStudentID())) {
                return this.studentList.get(i);
            }
        }
        return null;
    }

    @Override
    public Student getByName(String name) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setVisible(Student obj, boolean value) {
        for (Student student : this.studentList) {
            if (obj.getStudentID().equals(student.getStudentID())) {
                student.setStatus(value);
            }
        }
    }

    public Student contains(Student obj) {
        for (Student object : this.studentList) {
            if (object.getStudentID().equals(obj.getStudentID())) {
                return object;
            }
        }
        return null;
    }

    public int maxStudentID() {
        if (this.studentList.size() > 0) {
            return this.studentList.size();
        } else {
            return 0;
        }
    }
}
